//
//  WellcomViewController.swift
//  kingWeiBo
//
//  Created by King on 15/9/14.
//  Copyright © 2015年 King. All rights reserved.
//

import UIKit
import SDWebImage

class WellcomViewController: UIViewController {
    
    
    var constance: NSLayoutConstraint?
    
    override func viewDidAppear(animated: Bool) {
        constance!.constant = UIScreen.mainScreen().bounds.height - constance!.constant

        
        UIView.animateWithDuration(1.2, delay: 0.0, usingSpringWithDamping: 0.5, initialSpringVelocity: 5.0, options: UIViewAnimationOptions(rawValue: 0), animations: { () -> Void in
            self.view.layoutIfNeeded()
            
            }) { (_) -> Void in
            NSNotificationCenter.defaultCenter().postNotificationName(KNTongzhi, object: true)
        }
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

        setUpBackGround()
        let urlString = userAccount.shareAccount?.avatar_large
        iconView.sd_setImageWithURL(NSURL(string: urlString!))
    }

    
    func setUpBackGround(){
        view.addSubview(backGroundImage)
        view.addSubview(iconView)
        view.addSubview(textLable)
        
        iconView.translatesAutoresizingMaskIntoConstraints = false
        
        view.addConstraint(NSLayoutConstraint(item: iconView, attribute: NSLayoutAttribute.CenterX, relatedBy: NSLayoutRelation.Equal, toItem: view , attribute: NSLayoutAttribute.CenterX, multiplier: 1.0, constant: 0))
                view.addConstraint(NSLayoutConstraint(item: iconView, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil , attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1.0, constant: 90))
                view.addConstraint(NSLayoutConstraint(item: iconView, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: nil , attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1.0, constant: 90))
        
        view.addConstraint(NSLayoutConstraint(item: iconView, attribute: NSLayoutAttribute.CenterY, relatedBy: NSLayoutRelation.Equal, toItem: view, attribute: NSLayoutAttribute.CenterY, multiplier: 1.0, constant: 800))
        constance = view.constraints.last
        
        textLable.translatesAutoresizingMaskIntoConstraints = false
        view.addConstraint( NSLayoutConstraint(item: textLable, attribute: NSLayoutAttribute.CenterX, relatedBy: NSLayoutRelation.Equal, toItem: iconView, attribute: NSLayoutAttribute.CenterX, multiplier: 1.0, constant: 0))
        view.addConstraint( NSLayoutConstraint(item: textLable, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: iconView, attribute: NSLayoutAttribute.Bottom, multiplier: 1.0, constant: 16))
        
        
    }
   
//MARK: - 懒加载控件
    /// 背景图片
    private lazy var backGroundImage:UIImageView = UIImageView(image: UIImage(named: "ad_background"))
  
    ///头像
    private lazy var iconView :UIImageView = {
    
        let iconImage = UIImageView(image: UIImage(named: "avatar_default_big"))
        iconImage.layer.masksToBounds = true
        iconImage.layer.cornerRadius = 45
        return iconImage
    }()
    //文字
    private lazy var textLable:UILabel = {
        let txtLable = UILabel()
        txtLable.text = "欢迎回来"
        txtLable.sizeToFit()
        return txtLable
    }()
}
